using System.Text.Json.Serialization;

namespace AgentFrameworkDemo.Models;

/// <summary>
/// 工具定义模型
/// </summary>
public class ToolDefinition
{
    public string Id { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public string Description { get; set; } = string.Empty;
    public ToolType Type { get; set; }
    public Dictionary<string, ToolParameter> Parameters { get; set; } = new();
    public Dictionary<string, object> Configuration { get; set; } = new();
    public List<string> Tags { get; set; } = new();
    public bool Enabled { get; set; } = true;
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}

/// <summary>
/// 工具类型
/// </summary>
public enum ToolType
{
    Builtin,     // 内置工具
    McpServer,   // MCP服务器工具
    AgentTool,   // Agent转工具
    Custom       // 自定义工具
}

/// <summary>
/// 工具参数定义
/// </summary>
public class ToolParameter
{
    public string Name { get; set; } = string.Empty;
    public string Type { get; set; } = "string"; // string, number, boolean, array, object
    public string Description { get; set; } = string.Empty;
    public bool Required { get; set; } = false;
    public object? DefaultValue { get; set; }
    public Dictionary<string, object> Schema { get; set; } = new();
    public List<string>? EnumValues { get; set; }
}

/// <summary>
/// 工具执行请求
/// </summary>
public class ToolExecutionRequest
{
    public string ToolId { get; set; } = string.Empty;
    public Dictionary<string, object> Parameters { get; set; } = new();
    public string? SessionId { get; set; }
    public string? AgentId { get; set; }
    public Dictionary<string, object> Context { get; set; } = new();
    public TimeSpan? Timeout { get; set; }
}

/// <summary>
/// 工具执行结果
/// </summary>
public class ToolExecutionResult
{
    public bool Success { get; set; }
    public object? Result { get; set; }
    public string? ErrorMessage { get; set; }
    public string ToolId { get; set; } = string.Empty;
    public string ToolName { get; set; } = string.Empty;
    public TimeSpan ExecutionTime { get; set; }
    public DateTime ExecutedAt { get; set; } = DateTime.UtcNow;
    public Dictionary<string, object> Metadata { get; set; } = new();
    public ToolType ToolType { get; set; }
}

/// <summary>
/// MCP服务器配置
/// </summary>
public class McpServerConfig
{
    public string ServerId { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public string Endpoint { get; set; } = string.Empty;
    public Dictionary<string, object> Parameters { get; set; } = new();
    public List<string> AvailableTools { get; set; } = new();
    public bool Enabled { get; set; } = true;
    public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30);
}

/// <summary>
/// Agent转工具配置
/// </summary>
public class AgentToolConfig
{
    public string AgentId { get; set; } = string.Empty;
    public string AgentName { get; set; } = string.Empty;
    public string Description { get; set; } = string.Empty;
    public List<string> AllowedInputs { get; set; } = new(); // 允许的输入类型或模式
    public Dictionary<string, object> Parameters { get; set; } = new();
    public bool Enabled { get; set; } = true;
}